from sqlalchemy import BigInteger, False_
from sqlalchemy.orm import Mapped, mapped_column, relationship

from .base import TimedBaseModel


class User(TimedBaseModel):
    __tablename__ = "user"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str | None]
    telegram_id: Mapped[int | None] = mapped_column(BigInteger, unique=True)
    phone: Mapped[str] = mapped_column(unique=True)
    email: Mapped[str | None]
    onboarding: Mapped[bool] = mapped_column(server_default=False_())
    orders = relationship("Order", back_populates="user")

    def __repr__(self):
        return f"<User №{self.id} {self.telegram_id}>"

    def __str__(self):
        return self.__repr__()
